<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="admin_header.jsp">
    <jsp:param name="title" value="添加用户"/>
    <jsp:param name="active" value="users"/>
</jsp:include>

<!-- 主内容区 -->
<main role="main" class="col-md-10 ml-sm-auto px-4">
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">添加用户</h1>
    </div>

    <form action="userAdd" method="post" class="needs-validation" novalidate>
        <div class="mb-3">
            <label for="username" class="form-label">用户名</label>
            <input type="text" class="form-control" id="username" name="username" required>
            <div class="invalid-feedback">请输入用户名</div>
        </div>

        <div class="mb-3">
            <label for="password" class="form-label">密码</label>
            <input type="password" class="form-control" id="password" name="password" required>
            <div class="invalid-feedback">请输入密码</div>
        </div>

        <div class="mb-3">
            <label for="realname" class="form-label">真实姓名</label>
            <input type="text" class="form-control" id="realname" name="realname" required>
            <div class="invalid-feedback">请输入真实姓名</div>
        </div>

        <div class="mb-3">
            <label for="email" class="form-label">邮箱</label>
            <input type="email" class="form-control" id="email" name="email" required>
            <div class="invalid-feedback">请输入有效的邮箱地址</div>
        </div>

        <div class="mb-3">
            <label for="admin" class="form-label">用户角色</label>
            <select class="form-select" id="admin" name="admin" required>
                <option value="user">普通用户</option>
                <option value="admin">管理员</option>
            </select>
        </div>

        <button type="submit" class="btn btn-success">
            <i class="fas fa-check"></i> 保存
        </button>
        <a href="userManage" class="btn btn-secondary">
            <i class="fas fa-arrow-left"></i> 返回
        </a>
    </form>
</main>

<script>
// 表单验证
(function () {
    'use strict'
    var forms = document.querySelectorAll('.needs-validation')
    Array.prototype.slice.call(forms)
        .forEach(function (form) {
            form.addEventListener('submit', function (event) {
                if (!form.checkValidity()) {
                    event.preventDefault()
                    event.stopPropagation()
                }
                form.classList.add('was-validated')
            }, false)
        })
})()
</script>
</body>
</html> 